package com.starbaba.activity.view;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.google.gson.JsonObject;
import com.opensymphony.xwork2.ActionSupport;
import com.starbaba.activity.service.LoanHandPhoneConfigService;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.core.web.struts2.BaseAction;

@SuppressWarnings({"rawtypes", "unchecked", "serial"})
public class LoanHandPhoneConfigAction extends BaseAction {

	private LoanHandPhoneConfigService service;
	
	@Autowired
	@Qualifier("loanHandPhoneConfigService")
	public void setService(LoanHandPhoneConfigService service) {
		this.service = service;
	}
	
	public String showPage() {
		
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		try {
			this.service.showPage(paramsMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ActionSupport.SUCCESS;
		
	}
	
	public String showEditPage() {
		
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		try {
			this.service.showEditPage(paramsMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ActionSupport.SUCCESS;
		
	}
	
	public void queryList() {
		
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		parsePageRequest();
		PageResponse pageResponse = new PageResponse();
		int start = pageRequest.getIDisplayStart();
		int length = pageRequest.getIDisplayLength();
		
		try {
			List list = this.service.getList(start, length, pageResponse, paramsMap);
			pageResponse.setAaData(list);
			pageResponse.setSEcho(pageRequest.getSEcho());
			
			sendJsonMessage(JsonUtils.toJson(pageResponse, null, true, null, false));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void editInfo() {
		
		paramsMap = PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		try {
			String message = this.service.editInfo(paramsMap);
			JsonObject object = new JsonObject();
			object.addProperty("message", message);
			sendJsonMessage(object.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
}
